package com.ccp.dev.system.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.util.UUIDUtils;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.system.dao.SysVacationDao;
import com.ccp.dev.system.model.SysVacation;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * sys_vacation 信息操作服务类
 *
 * @author hw
 * @date 2019-10-11 10:08:54
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysVacationService extends BaseService<SysVacation> {

    @Resource
    private SysVacationDao sysVacationDao;

    /**
     *
     * @param sysVacations
     * @return
     */
    public int save(List<SysVacation> sysVacations){
        int result = 0;
        if(sysVacations.size() != 0){
            this.sysVacationDao.delByDataId(sysVacations.get(0).getDataId());
            String dataId = UUIDUtils.getUUIDFor32();
            for(int i=0;i<sysVacations.size();i++){
                if(StringUtil.isEmpty(sysVacations.get(i).getId())){
                    sysVacations.get(i).setId(UUIDUtils.getUUIDFor32());
                    sysVacations.get(i).setDataId(dataId);
                }else{
                    sysVacations.get(i).setDataId(dataId);
                }
            }
            result = this.baseDao.addList(sysVacations);
        }else{
            
        }
        return result;
    }

    /**
     * 根据标识位查询数据信息
     * @param dataId
     * @return
     */
    public List<SysVacation> querySysVacationsByDataId(String dataId){
        return sysVacationDao.querySysVacationsByDataId(dataId);
    }

    /**
     * 根据标识位删除数据信息
     * @param dataId
     * @return
     */
    public int delByDataId(String dataId){
        int result = 0;
        if(StringUtil.isNotEmpty(dataId)){
            String[] dataIds = dataId.split(",");
            for(int i=0;i<dataIds.length;i++){
                result += this.sysVacationDao.delByDataId(dataIds[i]);
            }
            return result;
        }else{
            return result;
        }
    }


}
